import 'package:flutter/material.dart';
import 'package:submail_one_login_flutter/sub_sdk.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
            child: Column(
          children: [
            ElevatedButton(
              child: const Text('getNetworkType'),
              onPressed: () async {
                final type = await SubSDK.getNetworkType();
                print("--------------subSDK.getNetworkType--------------");
                print("type: $type");
                print("");
              },
            ),
            ElevatedButton(
              child: const Text('getOperatorType'),
              onPressed: () async {
                final type = await SubSDK.getOperatorType();
                print("--------------subSDK.getOperatorType--------------");
                print("type: $type");
                print("");
              },
            ),
            ElevatedButton(
              child: const Text('init'),
              onPressed: () async {
                final (success, result) = await SubSDK.init(
                    androidConfig: SubPlatformConfig(
                        appId: '10109',
                        appKey: '5990eaf8d6a3466d29d463e801141bed'),
                    debug: true);
                print("--------------subSDK.init--------------");
                print("success: $success");
                print("result: $result");
                print("");
              },
            ),
            ElevatedButton(
              child: const Text('getLoginAccessCode'),
              onPressed: () async {
                final (success, result) = await SubSDK.getLoginAccessCode();
                print("--------------subSDK.getLoginAccessCode--------------");
                print("success: $success");
                print("result: ${result?.toJson()}");
                print("desc:${result?.desc}");
              },
            ),
            ElevatedButton(
                child: const Text('getLoginToken'),
                onPressed: () async {
                  final (success, result) = await SubSDK.getLoginToken();
                  print("--------------subSDK.getLoginToken--------------");
                  print("success: $success");
                  print("result: ${result?.toJson()}");
                  print("token: ${result?.token}");
                  print("");
                }),
            ElevatedButton(
                child: const Text('getPhoneNumber'),
                onPressed: () async {
                  final res = await SubSDK.getPhoneNumber();
                  print("--------------subSDK.getPhoneNumber--------------");
                  print("result: $res");
                  print("");
                }),
            ElevatedButton(
                child: const Text('delScrip'),
                onPressed: () => SubSDK.delScrip()),
            ElevatedButton(
                child: const Text('close'), onPressed: () => SubSDK.close())
          ],
        )),
      ),
    );
  }
}
